<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <label>施工单日期：</label>
                                <input style="width: 200px;" type="text" class="time-input" autocomplete="off" id="startTime" placeholder="开始时间" name="params[beginDdate]" data-format="yyyy-MM-dd HH:mm:ss"/>
                                <span>-</span>
                                <input style="width: 200px;" type="text" class="time-input" autocomplete="off" id="endTime" placeholder="结束时间" name="params[endDdate]" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </li>
                            <li>
                                <label>施工单单号：</label>
                                <input type="text" name="code"/>
                            </li>
                            <li>
                                <label>施工单种类：</label>
                                <select name="ctype">
                                    <option value="">所有</option>
                                    <option value="安装">安装</option>
                                    <option value="拆卸">拆卸</option>
                                    <option value="安装服务">安装服务</option>
                                    <option value="拆卸服务">拆卸服务</option>
                                </select>
                            </li>
                            <li>
                                <label>VIN码：</label>
                                <input type="text" name="vin"/>
                            </li>
                            <li>
                                <label>车型：</label>
                                <input type="text" name="carstd"/>
                            </li>
                            <li>
                                <label>门店：</label>
                                <input type="text" name="shopname"/>
                            </li>
                            <li>
                                <label>施工单状态：</label>
                                <select name="st">
                                    <option value="">所有</option>
                                    <option value="保存">保存</option>
                                    <option value="审核">审核</option>
                                </select>
                            </li>
                            <li>
                                <label>是否生成金蝶数据：</label>
                                <select name="kingSt">
                                    <option value="">所有</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </li>
                            <li>
                                <label>施工单保存人员：</label>
                                <input type="text" name="emp"/>
                            </li>
                            <li>
                                <label>施工单审核人员：</label>
                                <input type="text" name="creditemp"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="erp:setupbill:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="erp:setupbill:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="erp:setupbill:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="erp:setupbill:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('erp:setupbill:edit')}]];
        var removeFlag = [[${@permission.hasPermi('erp:setupbill:remove')}]];
        var prefix = ctx + "erp/setupbill";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/exportAll",
                modalName: "施工单信息",
                detailView: true,
                firstLoad: false,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'kingSt',
                        title: '生单状态',
                        visible:false
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            if(row.st == "保存"){
                                actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="review(\'' + row.id + '\')"><i class="fa fa-edit"></i>审核</a> ');
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            }
                            if(row.st == "审核"){
                                actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="reviewDis(\'' + row.id + '\')"><i class="fa fa-edit"></i>撤销审核</a> ');
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            }
                            if((row.ctype=="安装" || row.ctype == "拆卸") && row.kingSt == '否'){
                                actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="updateJDinfo(\'' + row.id + '\')"><i class="fa fa-warning"></i>生单</a>');
                            }
                            return actions.join('');
                        }
                    },
                {
                    field: 'ddate', 
                    title: '施工单日期'
                },
                {
                    field: 'code', 
                    title: '施工单单号'
                },
                {
                    field: 'ctype', 
                    title: '施工单种类'
                },
                {
                    field: 'shopname',
                    title: '销售仓库'
                },
                {
                    field: 'vin', 
                    title: 'VIN码'
                },
                {
                    field: 'vinpic', 
                    title: 'VIN图片',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a  href="javascript:void(0)" onclick="openVinPic(\'' + row.vinpic + '\')">查看</a> ');
                        return actions.join('');
                    }
                },
                {
                    field: 'carstd', 
                    title: '车型'
                },
                {
                    field: 'setuppic', 
                    title: '安装后的图片',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a  href="javascript:void(0)" onclick="openSetupPic(\'' + row.setuppic + '\')">查看</a> ');
                        return actions.join('');
                    }
                },
                    {
                        field: 'protectpic',
                        title: '施工保护图片',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a  href="javascript:void(0)" onclick="openSetupPic(\'' + row.protectpic + '\')">查看</a> ');
                            return actions.join('');
                        }
                    },
                   /* {
                        field: 'effectspic',
                        title: '施工效果图片',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a  href="javascript:void(0)" onclick="openSetupPic(\'' + row.effectspic + '\')">查看</a> ');
                            return actions.join('');
                        }
                    },*/
                {
                    field: 'st', 
                    title: '施工单状态'
                },
                {
                    field: 'sysdt', 
                    title: '施工时间'
                },{
                    field: 'setupemp',
                    title: '施工人员'
                },
                {
                    field: 'emp', 
                    title: '施工单保存人员'
                },
                {
                    field: 'creditemp', 
                    title: '施工单审核人员'
                },
                {
                    field: 'creditdt', 
                    title: '施工单审核时间'
                },
                    {
                        field: 'kingSt',
                        title: '是否生成金蝶数据'
                    },
                {
                    field: 'memo', 
                    title: '备注'
                }]
            };
            $.table.init(options);
        });
        initChildTable = function(index, row, $detail) {
            var orderStatus = row.st;
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: prefix + "/listChild",
                modalName: "修改施工信息",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    mid: row.id
                },
                columns: [
                    {
                        field: 'mcode',
                        title: '表头的单号'
                    },
                    {
                        field: 'itemcode',
                        title: '金蝶编码'
                    },
                    {
                        field: 'pcode',
                        title: '产品代码'
                    },
                    {
                        field: 'pname',
                        title: '产品名称'
                    },
                    {
                        field: 'pstd',
                        title: '产品规格'
                    },
                    {
                        field: 'punit',
                        title: '单位'
                    },
                    {
                        field: 'qty',
                        title: '施工单数量'
                    },
                    {
                        field: 'smemo',
                        title: '备注'
                    }]
            });

        };
        function review(id) {
            debugger;
            $.ajax({
                type: "post",
                url: ctx + "erp/setupbill/reviewSetupBill?id="+id,
                success: function(r) {
                    $.modal.msgSuccess("审批成功");
                }
            });
            $.table.refresh();
        }

        function reviewDis(id) {
            debugger;
            $.ajax({
                type: "post",
                url: ctx + "erp/setupbill/reviewDisSetupBill?id="+id,
                success: function(r) {
                    $.modal.msgSuccess("审批成功");
                }
            });
            $.table.refresh();
        }

        function openVinPic(vinpic){
            $.modal.open("查看图片", "http://www.gdhbsfndzkj.cn:8780"+vinpic);
        }
        function openSetupPic(setuppic){
            $.modal.open("查看图片", "http://www.gdhbsfndzkj.cn:8780"+setuppic);
        }

        function downloadFile(id) {
            debugger;
            $.ajax({
                type: "post",
                url: ctx + "erp/setupbill/getSetupBillById?id="+id,
                success: function(r) {
                    debugger;
                    $.ajax({
                        type: "get",
                        url: ctx + "common/download/resource?resource="+r.data.vinpic,
                        success: function(r) {
                            debugger;
                        }
                    });
                    $.ajax({
                        type: "get",
                        url: ctx + "common/download/resource?resource="+r.data.setuppic,
                        success: function(r) {
                            debugger;
                        }
                    });
                }
            });
            $.table.refresh();
        }

        function updateJDinfo(id) {
            $.ajax({
                type: "post",
                url: ctx + "erp/so/updateJDinfo?type=2&id="+id,
                success: function(r) {
                    $.modal.msgSuccess("生单成功");
                }
            });
            $.table.refresh();
        }
    </script>
</body>
</html>